package com.mcc.app.carbonEmission.service.impl;

import java.util.List;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mcc.app.carbonEmission.mapper.ReportEquipInfoMapper;
import com.mcc.app.carbonEmission.domain.ReportEquipInfo;
import com.mcc.app.carbonEmission.service.IReportEquipInfoService;

/**
 * 工序生产设施信息Service业务层处理
 *
 * @author gxy
 * @date 2025-07-04
 */
@Service
public class ReportEquipInfoServiceImpl implements IReportEquipInfoService {

    @Autowired
    private ReportEquipInfoMapper reportEquipInfoMapper;

    /**
     * 查询工序生产设施信息
     *
     * @param id 工序生产设施信息ID
     * @return 工序生产设施信息
     */
    @Override
    public ReportEquipInfo selectReportEquipInfoById(Long id) {
        return reportEquipInfoMapper.selectById(id);
    }

    /**
     * 查询工序生产设施信息列表
     *
     * @param reportEquipInfo 工序生产设施信息
     * @return 工序生产设施信息
     */
    @Override
    public List<ReportEquipInfo> selectReportEquipInfoList(ReportEquipInfo reportEquipInfo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (ObjectUtil.isNotEmpty(reportEquipInfo)) {
            queryWrapper.like(ObjectUtil.isNotEmpty(reportEquipInfo.getProcessName()), "process_name", reportEquipInfo.getProcessName());
            queryWrapper.like(ObjectUtil.isNotEmpty(reportEquipInfo.getProductName()), "product_name", reportEquipInfo.getProductName());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getProductCapacity()), "product_capacity", reportEquipInfo.getProductCapacity());
            queryWrapper.like(ObjectUtil.isNotEmpty(reportEquipInfo.getEquip1Name()), "equip1_name", reportEquipInfo.getEquip1Name());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getEquip1Spec()), "equip1_spec", reportEquipInfo.getEquip1Spec());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getEquip1Unit()), "equip1_unit", reportEquipInfo.getEquip1Unit());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getEquip1Runtime()), "equip1_runtime", reportEquipInfo.getEquip1Runtime());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getProductDay()), "product_day", reportEquipInfo.getProductDay());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getStopDay()), "stop_day", reportEquipInfo.getStopDay());
            queryWrapper.eq(ObjectUtil.isNotEmpty(reportEquipInfo.getMaintainDay()), "maintain_day", reportEquipInfo.getMaintainDay());
        }
        return reportEquipInfoMapper.selectList(queryWrapper);
    }

    /**
     * 新增工序生产设施信息
     *
     * @param reportEquipInfo 工序生产设施信息
     * @return 结果
     */
    @Override
    public int insertReportEquipInfo(ReportEquipInfo reportEquipInfo) {
        return reportEquipInfoMapper.insert(reportEquipInfo);
    }

    /**
     * 修改工序生产设施信息
     *
     * @param reportEquipInfo 工序生产设施信息
     * @return 结果
     */
    @Override
    public int updateReportEquipInfo(ReportEquipInfo reportEquipInfo) {
        return reportEquipInfoMapper.updateById(reportEquipInfo);
    }

    /**
     * 删除工序生产设施信息
     *
     * @param id 工序生产设施信息ID
     * @return 结果
     */
    @Override
    public int deleteReportEquipInfoById(Long id) {
        return reportEquipInfoMapper.deleteById(id);
    }

    /**
     * 批量删除工序生产设施信息
     *
     * @param ids 工序生产设施信息ID
     * @return 结果
     */
    @Override
    public int deleteReportEquipInfoByIds(Long[] ids) {
        if (ids.length == 0) return 0;
        return reportEquipInfoMapper.deleteBatchIds(ListUtil.toList(ids));
    }
}
